package lesson03;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpClientDemo01 {
    public static void main(String[] args) throws Exception {
        //1.建立一个socket
        DatagramSocket socket = new DatagramSocket(8080);
        //1.2建立一个能发送的包
        //发送的数据，地址
        String msg = "你好啊，服务器！";
        InetAddress localhost = InetAddress.getByName("localhost");
        int port = 9090;
        //包的内容：数据，数据长度，要发送给谁
        DatagramPacket packet = new DatagramPacket(msg.getBytes(),0,msg.getBytes().length,localhost,port);
        //2.发送包
        socket.send(packet);
        //关闭流
        socket.close();
    }
}
